package com.lancer.backlog.common.impl;

import com.lancer.backlog.common.bean.ResultBean;
import com.lancer.backlog.common.bean.StatusBean;
import com.lancer.backlog.common.exception.ApiException;
import com.lancer.backlog.common.exception.ParamException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * @author jq
 * @email 3601704681@qq.com
 * @date Created in  2020/8/20  20:36
 * @description TODO
 */
@ControllerAdvice
@ResponseBody
public class ResponseResultExceptionInterceptor {
    /**
     * 接口异常
     * @param e
     * @return
     */
    @ExceptionHandler(ApiException.class)
    public ResultBean apiException(ApiException e){
        return new ResultBean(StatusBean.SYSTEM_ERROR.getCode(),e.getMessage());
    }

    /**
     * 参数异常
     * @param e
     * @return
     */
    @ExceptionHandler(ParamException.class)
    public ResultBean paramException(ParamException e){
        return new ResultBean(StatusBean.PARAM_ERROR.getCode(),e.getMessage());
    }

    /**
     * SQL执行异常
     * @param e
     * @return
     */
    @ExceptionHandler(SQLException.class)
    public ResultBean sqlException(SQLException e){
        return new ResultBean(StatusBean.SYSTEM_ERROR.getCode(),"SQL执行失败");
    }

    /**
     * SQL执行异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResultBean exception(Exception e){
        return new ResultBean(StatusBean.SYSTEM_ERROR.getCode(),"内部执行异常");
    }


}
